<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="manage/layout :: common_header(~{::title})">
    <title>新闻管理-网站后台管理中心</title>
</head>
<body th:replace="manage/layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">

    <div class="sp-wrapper">

        <fieldset class="layui-elem-field">
            <legend>按条件搜索</legend>
            <div class="layui-field-box">
                <form class="layui-form layui-form-pane1" method="get" th:action="@{/manage/news_list}">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <input type="text" name="title" th:value="${title}" placeholder="标题" class="layui-input">
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <select name="categoryId" id="type">
                                    <option value="">新闻分类</option>
                                    <option th:each="item:${categoryList}" th:value="${item.id}" th:text="${item.name}">新闻</option>

                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-normal">搜索</button>
                            <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                        </div>

                        <div class="layui-inline">
                            <a class="layui-btn layui-btn-primary" th:href="@{/manage/news_add}">添加资讯</a>
                        </div>
                    </div>

                </form>
            </div>
        </fieldset>


            <table class="layui-table dd-table" lay-even lay-skin="row">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>图片</th>
                    <th>分类</th>
                    <th>语种</th>
                    <th>排序值</th>

                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="item:${list}">
                    <td class="center" th:text="${item.id}"></td>
                    <td class="center" th:text="${item.getTitle()}"></td>
                    <td><img th:src="${item.getImgUrl()}"></td>
                    <td class="center" th:text="${item.categoryName}"></td>
                    <td  >
                        <span th:if="${item.language!=null}" th:text="${T(com.huayi.website.entity.EnumLanguage).getName(item.language)}"></span>
                    </td>
                    <td class="center" th:text="${item.getSort()}"></td>

                    <td class="center" th:text="${item.getStatus()}"></td>
                    <td class="center">
                        <a class="layui-btn layui-btn-primary layui-btn-small"
                           th:href="@{/manage/news_edit(id=${item.getId()})}"><i class="layui-icon"></i>修改</a>

                        <a class="layui-btn layui-btn-primary layui-btn-small delete_data" th:attr="data-id=${item.id}" href="javascript:;">删除</a>
                    </td>
                </tr>
                </tbody>
            </table>

        <div class="layui-box layui-laypage layui-laypage-default">

        </div>
        <div class="layui-box layui-laypage layui-laypage-default pageBox">
            <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
        </div>


        <script type="text/javascript">
            //JavaScript代码区域
            layui.use(['jquery','form','layer'], function () {
                var $$ = layui.jquery;
                var form = layui.form;
                var layer = layui.layer;
                $$(function(){
                    var categoryId = '[[${categoryId}]]';
                    if(categoryId !='' ) {
                        $$("#type").val(categoryId);
                        form.render();
                    }

                    $$(".delete_data").click(function () {
                        if(confirm("删除不可逆，确定要删除吗？")){
                            var productId = $$(this).attr("data-id");
                            // alert(productId);
                            $$.ajax({
                                url: "/manage/news_delete",
                                type: "POST",
                                dataType: "JSON",
                                contentType: 'application/json',
                                data: JSON.stringify({id:productId}),
                                success: function (res) {
                                    if (res.code == 0) {
                                        alert("删除成功！");
                                        window.location.reload();
                                    } else {
                                        alert(res.msg);
                                    }


                                }
                            })
                        }
                    })
                })
            });
        </script>


    </div>
</div>
</body>
<html>
